\hypertarget{group___keyboard_controller}{
\section{KeyboardController}
\label{group___keyboard_controller}\index{KeyboardController@{KeyboardController}}
}
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_ga34599ca5c55cb9be3b235d7422aff45c}{
\#define \hyperlink{group___keyboard_controller_ga34599ca5c55cb9be3b235d7422aff45c}{KBC\_\-TIMEOUT}~30}
\label{group___keyboard_controller_ga34599ca5c55cb9be3b235d7422aff45c}

\begin{DoxyCompactList}\small\item\em maximum amount of milliseconds to wait for KBC response/availability \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{group___keyboard_controller_ga34242ce6ceb36ce79f32d2b339e74258}{kbd\_\-handler} (void)
\item 
int \hyperlink{group___keyboard_controller_gad0f35d8bf87c5a507aede8692c45f877}{write\_\-kbc\_\-cmd} (unsigned data)
\item 
int \hyperlink{group___keyboard_controller_gab19779ea7896435b3d4a5ff8a420f37e}{write\_\-kbc\_\-data} (unsigned data)
\item 
int \hyperlink{group___keyboard_controller_ga60b51b413d6f90bfb8dd7df85ddb63a2}{write\_\-aux} (unsigned cmd)
\item 
int \hyperlink{group___keyboard_controller_ga52a7ce44125208dfa303e597e6302a71}{read\_\-kbc} (void)
\item 
int \hyperlink{group___keyboard_controller_gad0f4763c978797b701c51fe3841ebdb0}{write\_\-kbc} (unsigned adr, unsigned data)
\end{DoxyCompactItemize}
\subsection*{The hardware register addresses}
\label{_amgrp372a25e47c984857a96cb8cf822c3828}
 \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_gabf7206ca2181c36ef04b795c9b64e886}{
\#define \hyperlink{group___keyboard_controller_gabf7206ca2181c36ef04b795c9b64e886}{CMD\_\-REG}~0x64}
\label{group___keyboard_controller_gabf7206ca2181c36ef04b795c9b64e886}

\begin{DoxyCompactList}\small\item\em command register (read only) \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga89c4d098b53809674457b1660b1af780}{
\#define \hyperlink{group___keyboard_controller_ga89c4d098b53809674457b1660b1af780}{STAT\_\-REG}~0x64}
\label{group___keyboard_controller_ga89c4d098b53809674457b1660b1af780}

\begin{DoxyCompactList}\small\item\em status register (write only) \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga71b8ba376f687142f60a82d18c2715e0}{
\#define \hyperlink{group___keyboard_controller_ga71b8ba376f687142f60a82d18c2715e0}{DATA\_\-REG}~0x60}
\label{group___keyboard_controller_ga71b8ba376f687142f60a82d18c2715e0}

\begin{DoxyCompactList}\small\item\em data register (read/write) \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Bit meanings in the status register}
\label{_amgrpcc3c1babe399c18ae5111c8ae432a682}
 \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_ga45967c9e25447ba853cf6fb4ac545fe6}{
\#define \hyperlink{group___keyboard_controller_ga45967c9e25447ba853cf6fb4ac545fe6}{OBF}~(1 $<$$<$ 0)}
\label{group___keyboard_controller_ga45967c9e25447ba853cf6fb4ac545fe6}

\begin{DoxyCompactList}\small\item\em Output Buffer Full. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga3c48b10907056351582baf9f6478598e}{
\#define \hyperlink{group___keyboard_controller_ga3c48b10907056351582baf9f6478598e}{IBF}~(1 $<$$<$ 1)}
\label{group___keyboard_controller_ga3c48b10907056351582baf9f6478598e}

\begin{DoxyCompactList}\small\item\em Input Buffer Full. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga1b41fd2be63532d4ab910f8b256c3811}{
\#define \hyperlink{group___keyboard_controller_ga1b41fd2be63532d4ab910f8b256c3811}{AUX}~(1 $<$$<$ 5)}
\label{group___keyboard_controller_ga1b41fd2be63532d4ab910f8b256c3811}

\begin{DoxyCompactList}\small\item\em 1 if data at DATA\_\-REG came from mouse interface \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga307ab71673e26ec42b28a3bca05d4cb5}{
\#define \hyperlink{group___keyboard_controller_ga307ab71673e26ec42b28a3bca05d4cb5}{PAR\_\-ERR}~(1 $<$$<$ 7)}
\label{group___keyboard_controller_ga307ab71673e26ec42b28a3bca05d4cb5}

\begin{DoxyCompactList}\small\item\em Parity Error. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gad16f61e2bf70f6c7685e826224ed177f}{
\#define \hyperlink{group___keyboard_controller_gad16f61e2bf70f6c7685e826224ed177f}{TO\_\-ERR}~(1 $<$$<$ 6)}
\label{group___keyboard_controller_gad16f61e2bf70f6c7685e826224ed177f}

\begin{DoxyCompactList}\small\item\em Timeout Error. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{\char`\"{}Historical\char`\"{} commands to send to DATA\_\-REG, response in DATA\_\-REG}
\label{_amgrp1716368a8a205f9cb3d6e123ef2ad7b2}
 \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_ga9f7743653801b79b2cf7c4a2707882ad}{
\#define \hyperlink{group___keyboard_controller_ga9f7743653801b79b2cf7c4a2707882ad}{ResetKBC}~0xFF}
\label{group___keyboard_controller_ga9f7743653801b79b2cf7c4a2707882ad}

\begin{DoxyCompactList}\small\item\em Reset the KBC interface. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gae1856867674001a426a9ffb156affcd2}{
\#define \hyperlink{group___keyboard_controller_gae1856867674001a426a9ffb156affcd2}{DefaultKBD}~0xF6}
\label{group___keyboard_controller_gae1856867674001a426a9ffb156affcd2}

\begin{DoxyCompactList}\small\item\em Set default scancode and repeat rate. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gaaa35612ed5d4fdbe8000df239239713e}{
\#define \hyperlink{group___keyboard_controller_gaaa35612ed5d4fdbe8000df239239713e}{DisableKBD}~0xF5}
\label{group___keyboard_controller_gaaa35612ed5d4fdbe8000df239239713e}

\begin{DoxyCompactList}\small\item\em Historical Disable keyboard. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga696342c5acdcc88677782c0f3133b549}{
\#define \hyperlink{group___keyboard_controller_ga696342c5acdcc88677782c0f3133b549}{EnableKBD}~0xF4}
\label{group___keyboard_controller_ga696342c5acdcc88677782c0f3133b549}

\begin{DoxyCompactList}\small\item\em Historical clear buffer and enable keyboard. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga5e6859fb7c74889de02b86f3a03fec56}{
\#define \hyperlink{group___keyboard_controller_ga5e6859fb7c74889de02b86f3a03fec56}{KBDRate}~0xF3}
\label{group___keyboard_controller_ga5e6859fb7c74889de02b86f3a03fec56}

\begin{DoxyCompactList}\small\item\em Keyboard repeat rate, one arg, bits 0-\/4 repeat rate, bits 5-\/6 start delay. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga59358190e83ceb32a586e77d01a536c6}{
\#define \hyperlink{group___keyboard_controller_ga59358190e83ceb32a586e77d01a536c6}{WriteLEDS}~0xED}
\label{group___keyboard_controller_ga59358190e83ceb32a586e77d01a536c6}

\begin{DoxyCompactList}\small\item\em Turn on/off KBD LEDS, one arg, one bit per led, bits 0-\/2, 0-\/off, 1-\/on. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga1762a3d7ed4ff016f09dd89a931ac871}{
\#define \hyperlink{group___keyboard_controller_ga1762a3d7ed4ff016f09dd89a931ac871}{SCROLL\_\-LOCK}~(1 $<$$<$ 0)}
\label{group___keyboard_controller_ga1762a3d7ed4ff016f09dd89a931ac871}

\begin{DoxyCompactList}\small\item\em SCROLL\_\-LOCK led for WriteLEDS command. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga4dec6ba83b643ca753f0be5b167b02ae}{
\#define \hyperlink{group___keyboard_controller_ga4dec6ba83b643ca753f0be5b167b02ae}{NUM\_\-LOCK}~(1 $<$$<$ 1)}
\label{group___keyboard_controller_ga4dec6ba83b643ca753f0be5b167b02ae}

\begin{DoxyCompactList}\small\item\em NUM\_\-\_\-LOCK led for WriteLEDS command. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga7d5d3b2ce697563a426c7fda967af9d7}{
\#define \hyperlink{group___keyboard_controller_ga7d5d3b2ce697563a426c7fda967af9d7}{CAPS\_\-LOCK}~(1 $<$$<$ 2)}
\label{group___keyboard_controller_ga7d5d3b2ce697563a426c7fda967af9d7}

\begin{DoxyCompactList}\small\item\em CAPS\_\-LOCK led for WriteLEDS command. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Response codes to commands/data written in DATA\_\-REG}
\label{_amgrp62016c23d116959053588abaf99205c0}
 \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_ga6f6489887e08bff4887d0bc5dcf214d8}{
\#define \hyperlink{group___keyboard_controller_ga6f6489887e08bff4887d0bc5dcf214d8}{ACK}~0xFA}
\label{group___keyboard_controller_ga6f6489887e08bff4887d0bc5dcf214d8}

\begin{DoxyCompactList}\small\item\em Acknowledge OK response. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga0ad9f0fd5fc87aa4630979da018fdb39}{
\#define \hyperlink{group___keyboard_controller_ga0ad9f0fd5fc87aa4630979da018fdb39}{Resend}~0xFE}
\label{group___keyboard_controller_ga0ad9f0fd5fc87aa4630979da018fdb39}

\begin{DoxyCompactList}\small\item\em Resend error response; on multibyte commands the whole command must be resent from the beginning. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga0f20a163dec609fb464cba845e043be8}{
\#define \hyperlink{group___keyboard_controller_ga0f20a163dec609fb464cba845e043be8}{Error}~0xFC}
\label{group___keyboard_controller_ga0f20a163dec609fb464cba845e043be8}

\begin{DoxyCompactList}\small\item\em Error. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Command codes to send to CMD\_\-REG, args, if exists, to DATA\_\-REG, return values in DATA\_\-REG}
\label{_amgrpdc724bbab76fd2644c24a001008cbe73}
 \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_ga99bbff320189ff927ad8d28b32d0a3e2}{
\#define \hyperlink{group___keyboard_controller_ga99bbff320189ff927ad8d28b32d0a3e2}{ReadCommand}~0x20}
\label{group___keyboard_controller_ga99bbff320189ff927ad8d28b32d0a3e2}

\begin{DoxyCompactList}\small\item\em Read Command\_\-Byte. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga177bb59d36f14c1024b2de1601693605}{
\#define \hyperlink{group___keyboard_controller_ga177bb59d36f14c1024b2de1601693605}{WriteCommand}~0x60}
\label{group___keyboard_controller_ga177bb59d36f14c1024b2de1601693605}

\begin{DoxyCompactList}\small\item\em Write Command\_\-Byte, one arg. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga884864c92108739e60113ca2079cbe71}{
\#define \hyperlink{group___keyboard_controller_ga884864c92108739e60113ca2079cbe71}{DisableMouse}~0xA7}
\label{group___keyboard_controller_ga884864c92108739e60113ca2079cbe71}

\begin{DoxyCompactList}\small\item\em Disable Mouse Interface. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gacaa321c74955e015d83da05cd321c0f8}{
\#define \hyperlink{group___keyboard_controller_gacaa321c74955e015d83da05cd321c0f8}{EnableMouse}~0xA8}
\label{group___keyboard_controller_gacaa321c74955e015d83da05cd321c0f8}

\begin{DoxyCompactList}\small\item\em Enable Mouse Interface. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gab47f9ef099e1f33e026e5ee549900624}{
\#define \hyperlink{group___keyboard_controller_gab47f9ef099e1f33e026e5ee549900624}{TestMouse}~0xA9}
\label{group___keyboard_controller_gab47f9ef099e1f33e026e5ee549900624}

\begin{DoxyCompactList}\small\item\em Test Mouse Interface, returns 0 if OK. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gaf555314895f7b6544624a51f22e3aeb0}{
\#define \hyperlink{group___keyboard_controller_gaf555314895f7b6544624a51f22e3aeb0}{Test8042}~0xAA}
\label{group___keyboard_controller_gaf555314895f7b6544624a51f22e3aeb0}

\begin{DoxyCompactList}\small\item\em Test KBC, returns 0x55 if sucess, 0xFC on error. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga5414bbfebe830e7887014106d3fd681e}{
\#define \hyperlink{group___keyboard_controller_ga5414bbfebe830e7887014106d3fd681e}{TestKBD}~0xAB}
\label{group___keyboard_controller_ga5414bbfebe830e7887014106d3fd681e}

\begin{DoxyCompactList}\small\item\em Test mouse, returns 0 if OK. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga69a0c992535a868edcb9362b52859914}{
\#define \hyperlink{group___keyboard_controller_ga69a0c992535a868edcb9362b52859914}{NDisableKBD}~0xAD}
\label{group___keyboard_controller_ga69a0c992535a868edcb9362b52859914}

\begin{DoxyCompactList}\small\item\em New (versus historical) Disable keyboard. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gace4e2548e5f13bab908c668fe5df5819}{
\#define \hyperlink{group___keyboard_controller_gace4e2548e5f13bab908c668fe5df5819}{NEnableKBD}~0xAE}
\label{group___keyboard_controller_gace4e2548e5f13bab908c668fe5df5819}

\begin{DoxyCompactList}\small\item\em New (versus historical) Enable keyboard. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga1ace60d764c21d4e3dfe01f6b9b401e0}{
\#define \hyperlink{group___keyboard_controller_ga1ace60d764c21d4e3dfe01f6b9b401e0}{WriteMouse}~0xD4}
\label{group___keyboard_controller_ga1ace60d764c21d4e3dfe01f6b9b401e0}

\begin{DoxyCompactList}\small\item\em Write Mouse, one arg, see \char`\"{}Commands for the Mouse\char`\"{}. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga01e50ef9f098e20f6b0b0429644862cf}{
\#define \hyperlink{group___keyboard_controller_ga01e50ef9f098e20f6b0b0429644862cf}{ResetPC}~0xFE}
\label{group___keyboard_controller_ga01e50ef9f098e20f6b0b0429644862cf}

\begin{DoxyCompactList}\small\item\em Reset PC (reboot). \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Bit meanings in the Command\_\-Byte}
\label{_amgrp22837900a5e0efd014657e1817de0ea4}
 (read/write with command ReadCommand/WriteCommand) \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_gafc6b776bcf10fb8d8c84c9e2a924025e}{
\#define \hyperlink{group___keyboard_controller_gafc6b776bcf10fb8d8c84c9e2a924025e}{INT\_\-1}~(1 $<$$<$ 0)}
\label{group___keyboard_controller_gafc6b776bcf10fb8d8c84c9e2a924025e}

\begin{DoxyCompactList}\small\item\em Enable generation of interrupts from keyboard. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga474732bbd6e6c485541a39fb44b88325}{
\#define \hyperlink{group___keyboard_controller_ga474732bbd6e6c485541a39fb44b88325}{INT\_\-12}~(1 $<$$<$ 1)}
\label{group___keyboard_controller_ga474732bbd6e6c485541a39fb44b88325}

\begin{DoxyCompactList}\small\item\em Enable generation of interrupts from mouse. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga9e6ea2b423d7213db16c4975aaf38899}{
\#define \hyperlink{group___keyboard_controller_ga9e6ea2b423d7213db16c4975aaf38899}{EN\_\-KBD}~(1 $<$$<$ 4)}
\label{group___keyboard_controller_ga9e6ea2b423d7213db16c4975aaf38899}

\begin{DoxyCompactList}\small\item\em Enable keyboard interface (zero enables, one disables). \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gaf9776e4566c3a77a7c3631530998f386}{
\#define \hyperlink{group___keyboard_controller_gaf9776e4566c3a77a7c3631530998f386}{EN\_\-MOUSE}~(1 $<$$<$ 5)}
\label{group___keyboard_controller_gaf9776e4566c3a77a7c3631530998f386}

\begin{DoxyCompactList}\small\item\em Enable mouse interface (zero enables, one disables). \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Bit meaning in first byte of mouse data packet}
\label{_amgrpe68d2a8ca3256ffc1615a6727eb1de3b}
 \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_ga08deb639aef83c70892a364261b09133}{
\#define \hyperlink{group___keyboard_controller_ga08deb639aef83c70892a364261b09133}{YOVF}~(1 $<$$<$ 7)}
\label{group___keyboard_controller_ga08deb639aef83c70892a364261b09133}

\begin{DoxyCompactList}\small\item\em X overflow. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gac3172c891b25dafed9ced2476aa03cf1}{
\#define \hyperlink{group___keyboard_controller_gac3172c891b25dafed9ced2476aa03cf1}{XOVF}~(1 $<$$<$ 6)}
\label{group___keyboard_controller_gac3172c891b25dafed9ced2476aa03cf1}

\begin{DoxyCompactList}\small\item\em Y overflow. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga5c610c7c656c4cf62564a959c30e0245}{
\#define \hyperlink{group___keyboard_controller_ga5c610c7c656c4cf62564a959c30e0245}{YSGN}~(1 $<$$<$ 5)}
\label{group___keyboard_controller_ga5c610c7c656c4cf62564a959c30e0245}

\begin{DoxyCompactList}\small\item\em Sign of data packet byte 3 (y movement). \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga1829ceaee57583878dbef19f0bc1a724}{
\#define \hyperlink{group___keyboard_controller_ga1829ceaee57583878dbef19f0bc1a724}{XSGN}~(1 $<$$<$ 4)}
\label{group___keyboard_controller_ga1829ceaee57583878dbef19f0bc1a724}

\begin{DoxyCompactList}\small\item\em Sign of data packet byte 2 (x movement). \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gab4abb667b74797a9a64f95d388c4da75}{
\#define \hyperlink{group___keyboard_controller_gab4abb667b74797a9a64f95d388c4da75}{MBT}~(1 $<$$<$ 2)}
\label{group___keyboard_controller_gab4abb667b74797a9a64f95d388c4da75}

\begin{DoxyCompactList}\small\item\em Middle button. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gabc6d7bd471913c986a226a3893174dfc}{
\#define \hyperlink{group___keyboard_controller_gabc6d7bd471913c986a226a3893174dfc}{RBT}~(1 $<$$<$ 1)}
\label{group___keyboard_controller_gabc6d7bd471913c986a226a3893174dfc}

\begin{DoxyCompactList}\small\item\em Right button. \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga6bec57496b9c9cc22e12e62997e5be91}{
\#define \hyperlink{group___keyboard_controller_ga6bec57496b9c9cc22e12e62997e5be91}{LBT}~(1 $<$$<$ 0)}
\label{group___keyboard_controller_ga6bec57496b9c9cc22e12e62997e5be91}

\begin{DoxyCompactList}\small\item\em Left button. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Utility macros to inquiry first byte of mouse data packet}
\label{_amgrp2e45ba3bddab92f558a292882a6f6d6c}
 \begin{DoxyCompactItemize}
\item 
\hypertarget{group___keyboard_controller_ga37a6485f1a57d53c63b242f8692c9868}{
\#define \hyperlink{group___keyboard_controller_ga37a6485f1a57d53c63b242f8692c9868}{LEFT\_\-BUTTON}(dt)~(((dt) \& LBT) == LBT)}
\label{group___keyboard_controller_ga37a6485f1a57d53c63b242f8692c9868}

\begin{DoxyCompactList}\small\item\em 1 if left button pressed \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga8f2cffb043cf466894e2019ea14c400d}{
\#define \hyperlink{group___keyboard_controller_ga8f2cffb043cf466894e2019ea14c400d}{RIGHT\_\-BUTTON}(dt)~(((dt) \& RBT) == RBT)}
\label{group___keyboard_controller_ga8f2cffb043cf466894e2019ea14c400d}

\begin{DoxyCompactList}\small\item\em 1 if right button pressed \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gacfa9590af87bbf796387e1c6e01ef5c3}{
\#define \hyperlink{group___keyboard_controller_gacfa9590af87bbf796387e1c6e01ef5c3}{MIDDLE\_\-BUTTON}(dt)~(((dt) \& MBT) == MBT)}
\label{group___keyboard_controller_gacfa9590af87bbf796387e1c6e01ef5c3}

\begin{DoxyCompactList}\small\item\em 1 if middle button pressed \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga43c087e52d2e7260fed09fc0cc7d5752}{
\#define \hyperlink{group___keyboard_controller_ga43c087e52d2e7260fed09fc0cc7d5752}{Y\_\-OVERFLOW}(dt)~(((dt) \& XOVF) == XOVF)}
\label{group___keyboard_controller_ga43c087e52d2e7260fed09fc0cc7d5752}

\begin{DoxyCompactList}\small\item\em 1 if overflow in x movement \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_ga8c9b6532dd05bc77e9bcef499868d98f}{
\#define \hyperlink{group___keyboard_controller_ga8c9b6532dd05bc77e9bcef499868d98f}{X\_\-OVERFLOW}(dt)~(((dt) \& YOVF) == YOVF)}
\label{group___keyboard_controller_ga8c9b6532dd05bc77e9bcef499868d98f}

\begin{DoxyCompactList}\small\item\em 1 if overflow in y movement \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gaaf66ab279fa7f3781953d0c4422a7790}{
\#define \hyperlink{group___keyboard_controller_gaaf66ab279fa7f3781953d0c4422a7790}{X\_\-SIGN}(dt)~(((dt) \& XSGN) == XSGN ? -\/1 : 1)}
\label{group___keyboard_controller_gaaf66ab279fa7f3781953d0c4422a7790}

\begin{DoxyCompactList}\small\item\em 1 if positive x movement, -\/1 if negative \item\end{DoxyCompactList}\item 
\hypertarget{group___keyboard_controller_gaab5db4b8ea62f4cce4c01f703f0c8592}{
\#define \hyperlink{group___keyboard_controller_gaab5db4b8ea62f4cce4c01f703f0c8592}{Y\_\-SIGN}(dt)~(((dt) \& YSGN) == YSGN ? -\/1 : 1)}
\label{group___keyboard_controller_gaab5db4b8ea62f4cce4c01f703f0c8592}

\begin{DoxyCompactList}\small\item\em 1 if positive y movement, -\/1 if negative \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Keyboard and Mouse related functions 

\subsection{Function Documentation}
\hypertarget{group___keyboard_controller_ga34242ce6ceb36ce79f32d2b339e74258}{
\index{KeyboardController@{KeyboardController}!kbd\_\-handler@{kbd\_\-handler}}
\index{kbd\_\-handler@{kbd\_\-handler}!KeyboardController@{KeyboardController}}
\subsubsection[{kbd\_\-handler}]{\setlength{\rightskip}{0pt plus 5cm}void kbd\_\-handler (void)}}
\label{group___keyboard_controller_ga34242ce6ceb36ce79f32d2b339e74258}
Initializes the KeyBoard Controller. If 'debug' is not 0 every read or write to the KBC, together with the read or writed data is echoed to the screen. In this mode the function name being executed is printed followed by a ':', add=xx means the I/O address written, and data=xx the data read or written.

A 1 is returned if a mouse is found.

The function starts to flush any pending data in the KBC, reading the data register until a timeout is received.

Then it enables the KBC mouse interface, send a MouseReset to the mouse and checks for the correct answer (0xFA, 0xAA then 0x00). If the mouse was detected, data streaming is disabled (StreamDisable), SampleRate is set to 100, Resolution is set to 8 counts/mm, Scaling is set to 1:1, the mouse interrupts generation are enabled at the KBC (not at the PIC!), and data streaming enabled (StreamEnable). All this (but StreamEnable) shouldn't be necessary, as MouseReset is supposed to do it properly.

The KBDRate is also set to its maximum speed.

Uses \hyperlink{group___keyboard_controller_gad0f35d8bf87c5a507aede8692c45f877}{write\_\-kbc\_\-cmd()}, \hyperlink{group___keyboard_controller_gab19779ea7896435b3d4a5ff8a420f37e}{write\_\-kbc\_\-data()}, \hyperlink{group___keyboard_controller_ga52a7ce44125208dfa303e597e6302a71}{read\_\-kbc()} and \hyperlink{group___keyboard_controller_ga60b51b413d6f90bfb8dd7df85ddb63a2}{write\_\-aux()}

Example Output generated with debug = 1: {\ttfamily 
\begin{DoxyPre}
read\_kbc: timeout
write\_kbc: add=64 data=d4
write\_kbc: add=60 data=ff
read\_kbc: data=fa
read\_kbc: data=aa
read\_kbc: data= 0
write\_kbc: add=60 data=f5
read\_kbc: data=fa
write\_kbc: add=64 data=a7
write\_kbc: add=64 data=d4
write\_kbc: add=60 data=f5
read\_kbc: data=fa
write\_kbc: add=60 data=f3
read\_kbc: data=fa
write\_kbc: add=60 data= 0
read\_kbc: data=fa
write\_kbc: add=64 data=d4
write\_kbc: add=60 data=f3
read\_kbc: data=fa
write\_kbc: add=64 data=d4
write\_kbc: add=60 data= a
read\_kbc: data=fa
write\_kbc: add=64 data=d4
write\_kbc: add=60 data=e8
read\_kbc: data=fa
write\_kbc: add=64 data=d4
write\_kbc: add=60 data= 1
read\_kbc: data=fa
write\_kbc: add=64 data=20
read\_kbc: data=45
write\_kbc: add=64 data=60
write\_kbc: add=60 data=47
read\_kbc: timeout
write\_kbc: add=60 data=f4
read\_kbc: data=fa
write\_kbc: add=64 data=a8
write\_kbc: add=64 data=d4
write\_kbc: add=60 data=f4
read\_kbc: data=fa
 \end{DoxyPre}
} \hypertarget{group___keyboard_controller_ga52a7ce44125208dfa303e597e6302a71}{
\index{KeyboardController@{KeyboardController}!read\_\-kbc@{read\_\-kbc}}
\index{read\_\-kbc@{read\_\-kbc}!KeyboardController@{KeyboardController}}
\subsubsection[{read\_\-kbc}]{\setlength{\rightskip}{0pt plus 5cm}int read\_\-kbc (void)}}
\label{group___keyboard_controller_ga52a7ce44125208dfa303e597e6302a71}
Returns the data read a the data register.

Waits for OBF on status register up to KBC\_\-TIMEOUT milliseconds, then reads and returns the data read at the data register. Returns -\/1 on timeout or transmission error. \hypertarget{group___keyboard_controller_ga60b51b413d6f90bfb8dd7df85ddb63a2}{
\index{KeyboardController@{KeyboardController}!write\_\-aux@{write\_\-aux}}
\index{write\_\-aux@{write\_\-aux}!KeyboardController@{KeyboardController}}
\subsubsection[{write\_\-aux}]{\setlength{\rightskip}{0pt plus 5cm}int write\_\-aux (unsigned {\em cmd})}}
\label{group___keyboard_controller_ga60b51b413d6f90bfb8dd7df85ddb63a2}
Send 'cmd' to the mouse, prefacing it with the WriteMouse command to the command register.

If a Resend reply is received from the KBC, it retries up to 3 times to write 'cmd', resending the whole sequence.

Uses \hyperlink{group___keyboard_controller_gad0f35d8bf87c5a507aede8692c45f877}{write\_\-kbc\_\-cmd()}, \hyperlink{group___keyboard_controller_gad0f4763c978797b701c51fe3841ebdb0}{write\_\-kbc()} and \hyperlink{group___keyboard_controller_ga52a7ce44125208dfa303e597e6302a71}{read\_\-kbc()} \hypertarget{group___keyboard_controller_gad0f4763c978797b701c51fe3841ebdb0}{
\index{KeyboardController@{KeyboardController}!write\_\-kbc@{write\_\-kbc}}
\index{write\_\-kbc@{write\_\-kbc}!KeyboardController@{KeyboardController}}
\subsubsection[{write\_\-kbc}]{\setlength{\rightskip}{0pt plus 5cm}int write\_\-kbc (unsigned {\em adr}, \/  unsigned {\em data})}}
\label{group___keyboard_controller_gad0f4763c978797b701c51fe3841ebdb0}
Write 'data' at IO address 'adr' , returning -\/1 on error or timeout.

Waits for IBF on status register , than writes data to 'adr', return -\/1 on timeout. \hypertarget{group___keyboard_controller_gad0f35d8bf87c5a507aede8692c45f877}{
\index{KeyboardController@{KeyboardController}!write\_\-kbc\_\-cmd@{write\_\-kbc\_\-cmd}}
\index{write\_\-kbc\_\-cmd@{write\_\-kbc\_\-cmd}!KeyboardController@{KeyboardController}}
\subsubsection[{write\_\-kbc\_\-cmd}]{\setlength{\rightskip}{0pt plus 5cm}int write\_\-kbc\_\-cmd (unsigned {\em data})}}
\label{group___keyboard_controller_gad0f35d8bf87c5a507aede8692c45f877}
Write 'data' to the command register, returning 0 for OK or -\/1 on timeout.

Uses \hyperlink{group___keyboard_controller_gad0f4763c978797b701c51fe3841ebdb0}{write\_\-kbc()} \hypertarget{group___keyboard_controller_gab19779ea7896435b3d4a5ff8a420f37e}{
\index{KeyboardController@{KeyboardController}!write\_\-kbc\_\-data@{write\_\-kbc\_\-data}}
\index{write\_\-kbc\_\-data@{write\_\-kbc\_\-data}!KeyboardController@{KeyboardController}}
\subsubsection[{write\_\-kbc\_\-data}]{\setlength{\rightskip}{0pt plus 5cm}int write\_\-kbc\_\-data (unsigned {\em data})}}
\label{group___keyboard_controller_gab19779ea7896435b3d4a5ff8a420f37e}
Returns 1 if a DOS mouse driver is installed, 0 if not.

Needed to know if a DOS mouse driver is installed in order to reinstall it at program end. Write 'data' to the data register, returning ACK, Error or -\/1 on timeout.

If a Resend reply is received from the KBC, it retries up to 3 times to write the data.

Uses \hyperlink{group___keyboard_controller_gad0f4763c978797b701c51fe3841ebdb0}{write\_\-kbc()} and \hyperlink{group___keyboard_controller_ga52a7ce44125208dfa303e597e6302a71}{read\_\-kbc()} 